+++
title = "SQL Scripting Best Practices"
date = "2020-04-22"
+++


About
=====

WIP

I plan on copying or referring to this file for best practices. I admit
I might break my own rules and if so, that\'s a bug!

Checklist
=========

-   Use the 80 column rule and strive for 70.
-   End file with a newline.
-   Keywords et al should use uppercase.
-   delete-trailing-whitespace
-   untabify
-   Avoid trailing comments
-   Prefer -- comments over ***comments***

Example checks
==============

```
theFile=path/to/file
grep -Iirn '^.\{71\}' ${theFile}
tail -c 1 ${theFile}
grep -Iirn '/\*\|\*/' ${theFile}
```

```
theFile=path/to/file
sqlformat \
\
--comma_first True\
--indent_columns \
--indent_width 4 \
--wrap_after 70 \
-k upper \
\
-o foo.sql \
\
${theFile}
```

War stories
===========

-   

See also
========

-   [UNIX-like Shell Scripting Best
    Practices](shell-scripting-best-practices.org)
-   <https://unix.stackexchange.com/questions/42898/find-any-lines-exceeding-a-certain-length>
-   <https://stackoverflow.com/questions/4631068/how-do-i-find-files-that-do-not-end-with-a-newline-linefeed#20687956>
-   <https://github.com/andialbrecht/sqlparse>
